package com.gxa.xly2024.controller;

import com.gxa.xly2024.dto.UserDTO;
import com.gxa.xly2024.pojo.User;
import com.gxa.xly2024.service.RoleService;
import com.gxa.xly2024.service.impl.UserServiceImpl;
import com.gxa.xly2024.vo.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@Api(value = "用户数据user",tags = "用户数据接口API")
@RequestMapping("/user")
public class UserController {

    /**
     java任意类型数组  jackson 会自动返回到页面  JSONArray
     List            jackson 会自动返回到页面  JSONArray
     Set             jackson 会自动返回到页面  JSONArray
     Map             jackson 会自动返回到页面  JSONObject
     java任意对象     jackson 会自动返回到页面  JSONObject
     */
    @Resource
    private UserServiceImpl userService;

    @GetMapping("/selectById")
    public Map<String, Object> selectUserById(Integer id) {
        return this.userService.selectUserById(id);
    }

    @GetMapping("/selectUserByLimit")
    public Map<String, Object> selectUserByLimit(UserVO userVO) {
        return this.userService.selectUserByLimit(userVO);
    }
//    public Map<String, Object> selectUserByLimit(@RequestParam Integer page, @RequestParam Integer limit) {
//        return this.userService.selectUserByLimit(page, limit);
//    }

    @PostMapping("/insert")
    public Map<String, Object> insert(@RequestBody User user) {   // 接收前端传递的json对象
        return this.userService.insert(user);
    }

    @PostMapping("/updateById")
    public Map<String, Object> updateById(@RequestBody User user) {   // 接收前端传递的json对象
        return this.userService.updateById(user);
    }

    @PostMapping("/deleteById")
    public Map<String, Object> deleteById(Integer id) {   // 接收前端传递的json对象
        return this.userService.deleteById(id);
    }

    @GetMapping("/selectEcharts")
    public Map<String, Object> selectEcharts() {
        return userService.selectEcharts();
    }

    @PostMapping("/login")
    @ApiOperation(value = "用户登录接口",notes = "验证用户的用户名和密码",httpMethod = "POST", response = String.class)
    public Map<String, Object> login(@RequestParam String username, @RequestParam String password, HttpServletRequest request) {
        return userService.login(username, password, request);
    }
}
